﻿Chenxin.UI.ApplyInfoManage = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: '/service/ContractApply/ContractApply.ashx',
    createGrid: function() {
		var _this=this;
		return new Chenxin.UI.MultiRowGrid({
			actionUrl:this.actionUrl+'?op=getlist',
			pageSize: 50,
            height:400,
            renderTo: 'applyinfo_table',
            id: 'applyinfo',
            baseParam: { showtype: 10 },
            hasCheckBox: false,
            scope: this,
			cellAlign:'left',
			modelId:'RecordId',
			title:'主营业务列表',
			autoLoad:false,
			createTitleTool: function() {
                return [{
                    text: '<span class="simple"></span>主营业务(买卖)',
					scope:_this,
					title:'主营业务(买卖)',
					handler:function(el){
						this.showTypeGrid(10,el.title);
					}
				},
				{
                    text: '<span class="simple"></span>主营业务(租赁)',
					scope:_this,
					title:'主营业务(租赁)',
					handler:function(el){
						this.showTypeGrid(20,el.title);
					}
				},
				{
                    text: '<span class="simple"></span>零散业务',
					scope:_this,
					title:'零散业务',
					handler:function(el){
						this.showTypeGrid(30,el.title);
					}
				},{
                    text: '<span class="simple"></span>其他业务',
					scope:_this,
					title:'其他业务',
					handler:function(el){
						this.showTypeGrid(40,el.title);
					}
				}];
			}
		});
    },
	showTypeGrid:function(showtype,title){
		showtype=showtype||10;
		if(this.grid.baseParam.showtype!=showtype){
			this.grid.baseParam.showtype=showtype;
			this.grid.reload();
			this.grid.setTitle(title+'列表');
		}
	},
    applyUrl:{
		main:'/page/Contract_ApplyInfo/MainBusinessApply.aspx',
		loose:'/page/Contract_ApplyInfo/LooseBusinessApply.aspx',
		other:'/page/Contract_ApplyInfo/OtherBusinessApply.aspx'
	},
	
/* 	cancle: function() {
    },
    loadinfo: function() {
        var _this = this;
        Chenxin.ajax({
            type: "get",
            dataType: "text",
            paramType: 'json',
            async:false,
            url: this.actionUrl,
            data: { op: 'getmodel', modelid: this.currentId },
            onSuccess: function(data, msg) {
                if (data) {
                    _this.currentArchiveInfo = data.model;
                }
            }
        });
    }, */
    initEvent: function() {
        var _this = this;
		
		
        //修改申请
		$('.x_btn_edit').live('click',function(){
			_this.currentId=$(this).attr('r');
			_this.operateRecord('edit');
		});
        //确认申请
		$('.x_btn_sure').live('click',function(){
			_this.currentId=$(this).attr('r');
			_this.operateRecord('confirm');
		
		});
        //确认申请
		$('.x_btn_show').live('click',function(){
			_this.currentId=$(this).attr('r');
			_this.operateRecord('view');
		
		});
        //删除申请
		$('.x_btn_del').live('click',function(){
			_this.currentId=$(this).attr('r');
			_this.del();	
		});
		
		
        $('#ipt_keywords').defText({
            deftxt: '请输入房源编号/地址'
        });
    },
    /* editApply: function(){
        // var _this = this;
		
		var row=this.grid.store.rows[this.grid.store.map[this.currentId].index];
        switch(row.BusinessType)
        {
            case 10:
            case 20:
                this.toCheckPermit('edit','/page/Contract_ApplyInfo/MainBusinessApply.aspx');
                break;
            case 30:
                this.toCheckPermit('edit', '/page/Contract_ApplyInfo/LooseBusinessApply.aspx');
                break;
            case 40:
                this.toCheckPermit('edit', '/page/Contract_ApplyInfo/OtherBusinessApply.aspx');
                break;
            default:
                this.toCheckPermit('edit','/page/Contract_ApplyInfo/MainBusinessApply.aspx');
                break;
        }
        
    },
    confirmApply: function(){
        var _this = this;
		 switch(_this.currentArchiveInfo.BusinessType)
        {
			case 10:
            case 20:
				// _this.toCheckPermit('confirm','/page/Contract_ApplyInfo/ConfirmMainBusinessApply.aspx');
				_this.toCheckPermit('confirm','/page/Contract_ApplyInfo/MainBusinessApply.aspx');
				 break;
			 case 30:
				// _this.toCheckPermit('confirm','/page/Contract_ApplyInfo/ConfirmScatteredBusinessApply.aspx');
				_this.toCheckPermit('confirm','/page/Contract_ApplyInfo/LooseBusinessApply.aspx');
				 break;
			 case 40:
				_this.toCheckPermit('confirm','/page/Contract_ApplyInfo/ConfirmOtherBusinessApply.aspx');
				 break;
			 default:
				_this.toCheckPermit('confirm','#');
				 break;
		}
    }, */
	operateRecord:function(op){		
		var row=this.grid.store.rows[this.grid.store.map[this.currentId].index];
		
		if((op=='edit'||op=='del')&&row.ConfirmType==1){
			alert('该记录已经确认，不能修改、删除，只能查看！');
			return;
		}
		
		var applyUrl='main';
		if(row.BusinessType==30){
			applyUrl='loose';
		}
		if(row.BusinessType==40){
			applyUrl='other';
		}
		this.toCheckPermit(op,this.applyUrl[applyUrl]);
	},
    /* // delApply: function(){
        // var _this = this;
        // if (!_this.currentId) {
            // alert('请先选择一条报备记录！');
            // return;
        // }
        // Chenxin.ajax({
            // type: "get",
            // dataType: "text",
            // paramType: 'json',
            // url: this.actionUrl,
            // data: { op: 'del', modelid: _this.currentId  },
            // onSuccess: function(data, msg) {
                // alert(msg);
                // if(data.permit!=undefined && data.permit){
                    // _this.grid.reload();   
                // }
            // }
        // });
    // }, */
    toCheckPermit: function(op, url){
        var _this = this;
        if (!_this.currentId) {
            alert('请先选择一条报备记录！');
            return;
        }
        Chenxin.Fn.checkPermit(_this.actionUrl,op,function(data,msg){
			if(data.permit!=undefined){
				_this.permit=data.permit;
				_this.msg = msg;	
			}
		},this,{ modelid: _this.currentId });
		if(_this.permit){			
			url+='?RecordId='+this.currentId+'&op='+op;
			if (op=='view')
				window.open(url);
			else
				window.location.href=url;
		}else{
			alert(_this.msg);
		}   
    },
    createSearch: function() {
        return new Chenxin.UI.ApplyInfoSearch({
            scope: this
        });
    },
    initComponent: function() {
        Chenxin.UI.ApplyInfoManage.superclass.initComponent.call(this);
		this.searchGrid();
    }
});

var columns = {
    /**主营业务模式表头*/
    mainHead: {
        operate: {
            head: '操作',
            width: 120,
            isLock: true,
            inExpand: false,
            renderer: function(val, c, row) {
                function createBtn(txt, cls) {
                    return '<a title="' + txt + '" r="' + row.RecordId + '" style="margin:0px 2px;cursor:pointer" class="x_btn_' + cls + '">' + txt + '</a>';
                }
                return createBtn('修改', 'edit') + createBtn('确认', 'sure') + createBtn('删除', 'del') + createBtn('查看', 'show');
            }
        },
        ctype: {
            head: '状态',
            width: 40
        },
        CreateTime: {
            head: '建档时间',
            width: 80,
            sortable: true
        },
        CreateUserName: {
            head: '建档人',
            width: 60,
            sortable: true,
            renderer: function(val) {
                return val.substr(0, 10);
            }
        },
        HouseCode: {
            head: '房源编号',
            width: 180,
            sortable: true
        },
        VBenderDepartName: {
            width: 100,
            items: {
                VenderDepartName: {
                    head: '房源门店',
                    width: 100,
                    sortable: false
                },
                BuyerDepartName: {
                    head: '客源门店',
                    width: 100,
                    sortable: false
                }
            }
        },
        VBenderName: {
            width: 80,
            items: {
                VenderName: {
                head: '上家姓名',
                width: 80,
                    sortable: false
                },
				
                BuyerName: {
                head: '下家姓名',
                width: 80,
                    sortable: false
                }
            }
        },
        CustomerSource: {
            head: '客户来源',
            width: 100,
            sortable: true
        },
        HouseAddress: {
            head: '房源地址',
            width: 200,
            sortable: true
        },
        HouseProperty: {
            head: '房源性质',
            width: 60,
            sortable: true,
            renderer: function(val) {
                return val == 0 ? '居住用房' : '非居住用房';
            }
        },
        BargainPrice: {
            head: '合同标的',
            width: 80,
            sortable: true,
            style: 'text-align:right'
        },
        VBStandardCommision: {
            width: 80,
            items: {
                VStandardCommision: {
                    head: '上家标准佣收',
                    width: 80,
                    sortable: false,
                    style: 'text-align:right'
                },
                BStandardCommision: {
                    head: '下家标准佣收',
                    width: 80,
                    sortable: false,
                    style: 'text-align:right'
                }
            }
        },
        VBRealCommision: {
            width: 80,
            items: {
                VRealCommision: {
                    head: '上家确认佣收',
                    width: 80,
                    sortable: false,
                    style: 'text-align:right'
                },
                BRealCommision: {
                    head: '下家确认佣金',
                    width: 80,
                    sortable: false,
                    style: 'text-align:right'
                }
            }
        },
        VB_Departs: {
            width: 180,
            items: {
                V_Departs: {
                    width: 180,
                    head: '上家门店',
                    sortable: false
                },
                B_Departs: {
                    width: 180,
                    head: '下家门店',
                    sortable: false
                }
            }
        },
        VB_Users: {
            width: 180,
            items: {
                V_Users: {
                    head: '上家经纪人',
                    width: 180,
                    sortable: false
                },
                B_Users: {
                    head: '下家经纪人',
                    width: 180,
                    sortable: false
                }
            }
        },
        VB_Points: {
            width: 80,
            items: {
                V_Points: {
                    head: '上家点数',
                    width: 80,
                    sortable: false
                },
                B_Points: {
                    head: '下家点数',
                    width: 80,
                    sortable: false
                }
            }
        },
        BudinessCode: {
            head: '成交编号',
            width: 120,
            sortable: true
        },
        DoneDay: {
            head: '成交日期',
            width: 100,
            sortable: true,
            renderer: function(val) {
                return val.substr(0, 10);
            }
        }
    },

    /**零散业务模式表头*/
    subHead: {
        operate: {
            head: '操作',
            width: 120,
            isLock: true,
            inExpand: false,
            renderer: function(val, c, row) {
                function createBtn(txt, cls) {
                    return '<a title="' + txt + '" r="' + row.RecordId + '" style="margin:0px 2px;cursor:pointer" class="x_btn_' + cls + '">' + txt + '</a>';
                }
                return createBtn('修改', 'edit') + createBtn('确认', 'sure') + createBtn('删除', 'del') + createBtn('查看', 'show');
            }
        },
        ctype: {
            head: '状态',
            width: 40
        },
        CreateTime: {
            head: '建档时间',
            width: 80,
            sortable: true,
            renderer: function(val) {
                return val.substr(0, 10);
            }
        },
        CreateUserName: {
            head: '建档人',
            width: 80,
            sortable: true
        },
        Community: {
            head: '项目名称',
            width: 100,
            sortable: true
        },
        HouseAddress: {
            head: '房源地址',
            width: 200,
            sortable: true,
            style: 'text-align:left'
        },
        Area: {
            head: '面积',
            width: 60,
            sortable: true
        },
        CurrentFloor: {
            head: '楼层',
            width: 50,
            renderer: function(val, c, row) {
                return (row.CurrentFloor ? row.CurrentFloor : '') + '/' + (row.TotalFloor ? row.TotalFloor : '');
            }
        },
        BargainPrice: {
            head: '合同标的',
            width: 80,
            sortable: true,
            style: 'text-align:right'
        },
        VBenderName: {
            width: 100,
            items: {
                VenderName: {
                    head: '上家姓名',
                    width: 100,
                    sortable: true
                },
                BuyerName: {
                    head: '下家姓名',
                    width: 100,
                    sortable: true
                }
            }
        },
        VBenderMobile: {
            width: 100,
            items: {
                VenderMobile: {
                    head: '上家电话',
                    width: 100,
                    sortable: true,
					renderer: function(val, c, row) {
						return (row.VenderMobile ? row.VenderMobile : '-') + '/' + (row.VenderPhone ? row.VenderPhone : '-');}
                },
                BuyerMobile: {
                    head: '下家电话',
                    width: 100,
                    sortable: true,
					renderer: function(val, c, row) {
						return (row.BuyerMobile ? row.BuyerMobile : '-') + '/' + (row.BuyerPhone ? row.BuyerPhone : '-');}
                }
            }
        },
        CustomerSource: {
            head: '客户来源',
            width: 100,
            sortable: true
        },
        VBRealCommision: {
            width: 120,
            items: {
                VRealCommision: {
                    head: '上家确认佣收',
                    width: 120,
                    sortable: true,
                    style: 'text-align:right'
                },
                BRealCommision: {
                    head: '下家确认佣金',
                    width: 120,
                    sortable: true,
                    style: 'text-align:right'
                }
            }
        },
        VBCommision: {
            width: 100,
            items: {
                VCommision: {
                    head: '上家折佣',
                    width: 100,
                    sortable: true,
                    style: 'text-align:right'
                },
                BCommision: {
                    head: '下家折佣',
                    width: 100,
                    sortable: true,
                    style: 'text-align:right'
                }
            }
        },
        VBConsulting: {
            width: 100,
            items: {
                VConsulting: {
                    head: '上家咨询费',
                    width: 100,
                    sortable: true,
                    style: 'text-align:right'
                },
                BConsulting: {
                    head: '下家咨询费',
                    width: 100,
                    sortable: true,
                    style: 'text-align:right'
                }
            }
        },
        Departs: {
            head: '门店',
            width: 200,
            sortable: true
        },
        Users: {
            head: '业务员',
            width: 150,
            sortable: true
        },
        Points: {
            head: '点数',
            width: 120,
            sortable: true
        },
        BudinessCode: {
            head: '成交编号',
            width: 140,
            sortable: true
        },
        DoneDay: {
            head: '成交日期',
            width: 100,
            sortable: true,
            renderer: function(val) {
                return val.substr(0, 10);
            }
        }
    },

    /**其他业务模式表头*/
    otherHead: {
        operate: {
            head: '操作',
            width: 120,
            isLock: true,
            inExpand: false,
            renderer: function(val, c, row) {
                var _this = this;
                function createBtn(txt, cls) {
                    return '<a title="' + txt + '" r="' + row.RecordId + '" style="margin:0px 2px;" class="x_btn_' + cls + '">' + txt + '</a>';
                }
                return createBtn('修改', 'edit') + createBtn('确认', 'sure') + createBtn('删除', 'del') + createBtn('查看', 'show');
            }
        },
        ctype: {
            head: '状态',
            width: 40
        },
        CreateTime: {
            head: '建档时间',
            width: 100,
            sortable: true,
            renderer: function(val) {
                return val.substr(0, 10);
            }
        },
        CreateUserName: {
            head: '建档人',
            width: 80,
            sortable: true
        },
		VBenderName: {
            width: 100,
            items: {
                VenderName: {
                    head: '上家姓名',
                    width: 100,
                    sortable: true
                },
                BuyerName: {
                    head: '下家姓名',
                    width: 100,
                    sortable: true
                }
            }
        },
        VBenderMobile: {
            width: 100,
            items: {
                VenderMobile: {
                    head: '上家电话',
                    width: 100,
                    sortable: true,
					renderer: function(val, c, row) {
						return (row.VenderMobile ? row.VenderMobile : '-') + '/' + (row.VenderPhone ? row.VenderPhone : '-');}
                },
                BuyerMobile: {
                    head: '下家电话',
                    width: 100,
                    sortable: true,
					renderer: function(val, c, row) {
						return (row.BuyerMobile ? row.BuyerMobile : '-') + '/' + (row.BuyerPhone ? row.BuyerPhone : '-');}
                }
            }
        },
        CustomerSource: {
            head: '客户来源',
            width: 100,
            sortable: true
        },
        VBRealCommision: {
            width: 120,
            items: {
                VRealCommision: {
                    head: '上家确认佣收',
                    width: 120,
                    sortable: true,
                    style: 'text-align:right'
                },
                BRealCommision: {
                    head: '下家确认佣金',
                    width: 120,
                    sortable: true,
                    style: 'text-align:right'
                }
            }
        },
        VBCommision: {
            width: 100,
            items: {
                VCommision: {
                    head: '上家折佣',
                    width: 100,
                    sortable: true,
                    style: 'text-align:right'
                },
                BCommision: {
                    head: '下家折佣',
                    width: 100,
                    sortable: true,
                    style: 'text-align:right'
                }
            }
        },
        VBConsulting: {
            width: 100,
            items: {
                VConsulting: {
                    head: '上家咨询费',
                    width: 100,
                    sortable: true,
                    style: 'text-align:right'
                },
                BConsulting: {
                    head: '下家咨询费',
                    width: 100,
                    sortable: true,
                    style: 'text-align:right'
                }
            }
        },
        Departs: {
            head: '门店',
            width: 200,
            sortable: true
        },
        Users: {
            head: '业务员',
            width: 150,
            sortable: true
        },
        Points: {
            head: '点数',
            width: 120,
            sortable: true
        },
        BudinessCode: {
            head: '成交编号',
            width: 140,
            sortable: true
        },
        DoneDay: {
            head: '成交日期',
            width: 70,
            sortable: true,
            renderer: function(val) {
                return val.substr(0, 10);
            }
        }
    }
}

/**
*查询面板
*/
Chenxin.UI.ApplyInfoSearch = Chenxin.extend(Chenxin.UI.SearchCommon, {
    id: 'applyinfo_search',
    initEvent: function() {
        var _this = this;
        //查询
        $('#btn_search').click(function() {
		    _this.scope.reloadGrid(_this.scope.search.getParamJson());
        });
		
		var curdate=new Date();
		
		$('#starttime').defText({
            deftxt: '开始日期'
        });
        $('#eTime').defText({
            deftxt: '结束日期'
        });
		
		$('#starttime').val(curdate.getFullYear() + '-'+(curdate.getMonth()+1) +'-1');
		if(curdate.getMonth()+1 == 12)
		    $('#eTime').val(curdate.getFullYear()+1 + '-1-1');
		else
		    $('#eTime').val(curdate.getFullYear() + '-'+(curdate.getMonth()+2) +'-1');
		
	},
    createComboList: function() {
    
        //合同类型
        var businesstype = new Chenxin.UI.Combo({
            containerId: '#BusinessType',
            tbxWidth: 45,
            items: comboCommon.ApplyBusinessType
        });
        
        //状态
        var confirmtype = new Chenxin.UI.Combo({
            containerId: '#ConfirmType',
            tbxWidth: 45,
			initValue:0,
            items: comboCommon.ApplyConfirmType
        });
        
        var combl = new Chenxin.UI.StructComboList();
        var structs = combl.comboList;
        structs.push(businesstype);
        structs.push(confirmtype);
        
        return structs;
    },
    initComponent: function() {
        Chenxin.UI.ApplyInfoSearch.superclass.initComponent.call(this);
    }
});

getcity = true; //设置需要获取城市下拉框数据

$(document).ready(function() {
    var ApplyInfoMgr = new Chenxin.UI.ApplyInfoManage();
});